#!/bin/sh

OUTPUT_DIR="OUTPUT"
DEB_OUTPUT_DIR=$OUTPUT_DIR/deb
TARBALL_OUTPUT_DIR=$OUTPUT_DIR/tarball
CODEDOC_OUTPUT_DIR=$OUTPUT_DIR/codedoc
DOC_OUTPUT_DIR=$OUTPUT_DIR/documentation

rm -rf $OUTPUT_DIR
mkdir -p $DEB_OUTPUT_DIR $TARBALL_OUTPUT_DIR $CODEDOC_OUTPUT_DIR $DOC_OUTPUT_DIR

cd documentation
sh generate-pdf.sh
cp output/predesys-doc-*.pdf ../$DOC_OUTPUT_DIR
cd ..

PACKAGE=predesys-server
cd $PACKAGE/scripts
sh generate-deb.sh
sh generate-codedoc.sh
cp output/$PACKAGE_*.deb ../../$DEB_OUTPUT_DIR
cp output/$PACKAGE-*.tar.gz ../../$TARBALL_OUTPUT_DIR
cp -r output/$PACKAGE-*-codedoc ../../$CODEDOC_OUTPUT_DIR
cd ../..

PACKAGE=predesys-service-api
cd $PACKAGE/scripts
sh generate-deb.sh
cp output/$PACKAGE_*.deb ../../$DEB_OUTPUT_DIR
cp output/$PACKAGE-*.tar.gz ../../$TARBALL_OUTPUT_DIR
cd ../..

PACKAGE=predesys-bluetooth-radar
cd $PACKAGE/scripts
sh generate-deb.sh
cp output/$PACKAGE_*.deb ../../$DEB_OUTPUT_DIR
cp output/$PACKAGE-*.tar.gz ../../$TARBALL_OUTPUT_DIR
cd ../..

PACKAGE=predesys-lan-radar
cd $PACKAGE/scripts
sh generate-deb.sh
cp output/$PACKAGE_*.deb ../../$DEB_OUTPUT_DIR
cp output/$PACKAGE-*.tar.gz ../../$TARBALL_OUTPUT_DIR
cd ../..

PACKAGE=predesys-people-presence
cd $PACKAGE/scripts
sh generate-deb.sh
cp output/$PACKAGE_*.deb ../../$DEB_OUTPUT_DIR
cp output/$PACKAGE-*.tar.gz ../../$TARBALL_OUTPUT_DIR
cd ../..

PACKAGE=ppclient
cd $PACKAGE/scripts
sh generate-deb.sh
cp output/$PACKAGE_*.deb ../../$DEB_OUTPUT_DIR
cp output/$PACKAGE-*.tar.gz ../../$TARBALL_OUTPUT_DIR
cd ../..

echo "All packages generated successfully into OUTPUT folder."
